import 'dart:convert';

import 'package:flutter_application_cyber/model/cn_userInfo_model.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart'; //ChangeNotifier需要material素材库


T? asT<T>(dynamic value) {
  if (value is T) {
    return value;
  }
  return null;
}
//登录接口返回数据
class HDHResponse {
  HDHResponse({
    this.data,
    this.statuscode,
    this.statusmessage,
    // this.hashcode,
  });

//json == null ? null :
  factory HDHResponse.fromJson(Map<String, dynamic> json) => HDHResponse(
        data:
            HDHResponseData.fromJson(asT<Map<String, dynamic>>(json['data'])!),
        statuscode: asT<int>(json['statusCode']),
        statusmessage: asT<String>(json['statusMessage']),
        // hashcode: asT<int>(json['hashCode']),
      );

  dynamic data;
  int? statuscode;
  String? statusmessage;
  // int? hashcode;

  @override
  String toString() {
    return jsonEncode(this);
  }

  Map<String, dynamic> toJson() => <String, dynamic>{
        'data': data,
        'statusCode': statuscode,
        'statusMessage': statusmessage,
        // 'hashCode': hashcode,
      };
}

class HDHResponseData {
  HDHResponseData({
    this.code,
    this.data,
    this.fail,
    this.key,
    this.success,
    this.msg
  });

//json == null ? null :
  factory HDHResponseData.fromJson(Map<String, dynamic> json) =>
      HDHResponseData(
        code: asT<int>(json['code']),
        success: asT<bool>(json['success']),
        msg: asT<String>(json['msg']),
        data: json['data'],
      );


  int? code;
  bool? fail;
  String? key;
  bool? success;
  String? msg;
  dynamic data;


  @override
  String toString() {
    return jsonEncode(this);
  }

  Map<String, dynamic> toJson() => <String, dynamic>{
        'code': code,
        'success': success,
        'key': key,
        'fail': fail,
        'data': data,
        'msg': msg,
      };
}

class UserData{

   UserData({
   
    this.userInfo,
    this.isFirstRegister,
    this.token,
  
  });

//json == null ? null :
  factory UserData.fromJson(Map<String, dynamic> json) =>
      UserData(
        isFirstRegister: asT<String>(json['isFirstRegister']),
        token: asT<String>(json['token']),
        userInfo: CnUserModel.coverFromJson(json['userInfo']),
      );

  String? isFirstRegister;
  String? token;
  CnUserModel? userInfo;


  @override
  String toString() {
    return jsonEncode(this);
  }

  Map<String, dynamic> toJson() => <String, dynamic>{
        'isFirstRegister': isFirstRegister,
        'token': token,
        'userInfo': userInfo,
      };

}

class HDHResponseDataHeader {
  HDHResponseDataHeader({
    this.retn,
    this.desc,
  });

//json == null ? null :
  factory HDHResponseDataHeader.fromJson(Map<String, dynamic>? json) =>
      HDHResponseDataHeader(
        retn: asT<String>(json?['Retn']),
        desc: asT<String>(json?['Desc']),
      );

  String? retn;
  String? desc;

  @override
  String toString() {
    return jsonEncode(this);
  }

  Map<String, dynamic> toJson() => <String, dynamic>{
        'Retn': retn,
        'Desc': desc,
      };
}



//获取app配置返回数据
class ConfigModelData {
  String? ver;
  List<ConfigItemsModel>? items;

  ConfigModelData({this.ver, this.items});

  ConfigModelData.fromJson(Map<String, dynamic> json) {
    ver = json['ver'];
    if (json['items'] != null) {
      items = <ConfigItemsModel>[];
      json['items'].forEach((v) {
        items!.add(new ConfigItemsModel.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['ver'] = this.ver;
    if (this.items != null) {
      data['items'] = this.items!.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

class ConfigItemsModel {
  String? data;
  String? name;

  ConfigItemsModel({this.data, this.name});

  ConfigItemsModel.fromJson(Map<String, dynamic> json) {
    data = json['data'].toString() ;
    name = json['name'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['data'] = this.data;
    data['name'] = this.name;
    return data;
  }
}

//用户数据

class UserInfoModel {
  String? userId;
  int? userType;
  String? nickname;
  bool? isInternal;
  String? avatar;
  String? avatarUrl;
  String? avatarThumbUrl;
  String? avatarMiddleThumbUrl;
  List<Null>? mediumList;
  List<AvatarRespList>? avatarRespList;
  int? gender;
  String? birthday;
  int? age;
  String? country;
  String? pkgName;
  List<MediaModel>? mediaList;
  bool? isAnswer;
  int? availableCoins;
  int? auditStatus;
  bool? isShowReviewSupplementTips;
  List<String>? tagsList;
  List<TagDetails>? tagDetails;
  String? rongcloudToken;
  bool? isRecharge;
  bool? isVip;
  int? level;
  int? followNum;
  int? praiseNum;
  bool? isBlock;
  bool? isFollow;
  bool? isSwitchNotDisturbIm;
  bool? isSwitchNotDisturbCall;
  bool? isHavePassword;
  bool? isReview;
  bool? isMultiple;
  String? registerPkgName;
  String? registerCountry;
  String? loginPkgName;
  bool? hasEquity;
  String? createTime;
  String? about;

  UserInfoModel(
      {this.userId,
      this.userType,
      this.nickname,
      this.isInternal,
      this.avatar,
      this.avatarUrl,
      this.avatarThumbUrl,
      this.avatarMiddleThumbUrl,
      this.mediumList,
      this.avatarRespList,
      this.gender,
      this.birthday,
      this.age,
      this.country,
      this.pkgName,
      this.mediaList,
      this.isAnswer,
      this.availableCoins,
      this.auditStatus,
      this.isShowReviewSupplementTips,
      this.tagsList,
      this.tagDetails,
      this.rongcloudToken,
      this.isRecharge,
      this.isVip,
      this.level,
      this.followNum,
      this.praiseNum,
      this.isBlock,
      this.isSwitchNotDisturbIm,
      this.isSwitchNotDisturbCall,
      this.isHavePassword,
      this.isReview,
      this.isMultiple,
      this.registerPkgName,
      this.registerCountry,
      this.loginPkgName,
      this.hasEquity,
      this.isFollow,
      this.createTime,
      this.about
      });

  UserInfoModel.fromJson(Map<String, dynamic> json) {
    userId = json['userId'];
    userType = json['userType'];
    nickname = json['nickname'];
    isInternal = json['isInternal'];
    avatar = json['avatar'];
    avatarUrl = json['avatarUrl'];
    avatarThumbUrl = json['avatarThumbUrl'];
    avatarMiddleThumbUrl = json['avatarMiddleThumbUrl'];
    if (json['mediumList'] != null) {
      mediumList = <Null>[];
      json['mediumList'].forEach((v) {
        // mediumList!.add(new Null.fromJson(v));
      });
    }
    if (json['avatarRespList'] != null) {
      avatarRespList = <AvatarRespList>[];
      json['avatarRespList'].forEach((v) {
        avatarRespList!.add(new AvatarRespList.fromJson(v));
      });
    }
    gender = json['gender'];
    birthday = json['birthday'];
    age = json['age'];
    country = json['country'];
    pkgName = json['pkgName'];
    if (json['mediaList'] != null) {
      mediaList = <MediaModel>[];
      json['mediaList'].forEach((v) {
           mediaList!.add(new MediaModel.fromJson(v));
      });
    }
    isAnswer = json['isAnswer'];
    availableCoins = json['availableCoins']??0;
    auditStatus = json['auditStatus'];
    isShowReviewSupplementTips = json['isShowReviewSupplementTips'];
    tagsList = (json['tagsList']??[]).cast<String>();
    if (json['tagDetails'] != null) {
      tagDetails = <TagDetails>[];
      json['tagDetails'].forEach((v) {
        tagDetails!.add(new TagDetails.fromJson(v));
      });
    }
    rongcloudToken = json['rongcloudToken'];
    isRecharge = json['isRecharge']??false;
    isVip = json['isVip'];
    level = json['level'];
    followNum = json['followNum'];
    praiseNum = json['praiseNum'];
    isBlock = json['isBlock'];
    isFollow = false;
    isSwitchNotDisturbIm = json['isSwitchNotDisturbIm'];
    isSwitchNotDisturbCall = json['isSwitchNotDisturbCall'];
    isHavePassword = json['isHavePassword'];
    isReview = json['isReview'];
    isMultiple = json['isMultiple'];
    registerPkgName = json['registerPkgName'];
    registerCountry = json['registerCountry'];
    loginPkgName = json['loginPkgName'];
    hasEquity = json['hasEquity'];
    createTime = json['createTime'];
    about = json['about'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['userId'] = this.userId;
    data['userType'] = this.userType;
    data['nickname'] = this.nickname;
    data['isInternal'] = this.isInternal;
    data['avatar'] = this.avatar;
    data['avatarUrl'] = this.avatarUrl;
    data['avatarThumbUrl'] = this.avatarThumbUrl;
    data['avatarMiddleThumbUrl'] = this.avatarMiddleThumbUrl;
    if (this.mediumList != null) {
      data['mediumList'] = '';
    }
    if (this.avatarRespList != null) {
      data['avatarRespList'] =
          this.avatarRespList!.map((v) => v.toJson()).toList();
    }
    data['gender'] = this.gender;
    data['birthday'] = this.birthday;
    data['age'] = this.age;
    data['country'] = this.country;
    data['pkgName'] = this.pkgName;
    if (this.mediaList != null) {
      data['mediaList'] = this.mediaList!.map((v) => v.toJson()).toList();
    }
    data['isAnswer'] = this.isAnswer;
    data['availableCoins'] = this.availableCoins;
    data['auditStatus'] = this.auditStatus;
    data['isShowReviewSupplementTips'] = this.isShowReviewSupplementTips;
    data['tagsList'] = this.tagsList;
    if (this.tagDetails != null) {
      data['tagDetails'] = this.tagDetails!.map((v) => v.toJson()).toList();
    }
    data['rongcloudToken'] = this.rongcloudToken;
    data['isRecharge'] = this.isRecharge;
    data['isVip'] = this.isVip;
    data['level'] = this.level;
    data['followNum'] = this.followNum;
    data['praiseNum'] = this.praiseNum;
    data['isBlock'] = this.isBlock;
    data['isSwitchNotDisturbIm'] = this.isSwitchNotDisturbIm;
    data['isSwitchNotDisturbCall'] = this.isSwitchNotDisturbCall;
    data['isHavePassword'] = this.isHavePassword;
    data['isReview'] = this.isReview;
    data['isMultiple'] = this.isMultiple;
    data['registerPkgName'] = this.registerPkgName;
    data['registerCountry'] = this.registerCountry;
    data['loginPkgName'] = this.loginPkgName;
    data['hasEquity'] = this.hasEquity;
    data['createTime'] = this.createTime;

    data['about'] = this.about;
    return data;
  }
}
class ChangeUserInfoModel extends ChangeNotifier{
  UserInfoModel  _info = UserInfoModel();
  UserInfoModel  get info => _info ;
  void setInfo(info){
    _info = info;
    notifyListeners();
  }

  void setCoins(int coins){
    _info.availableCoins =coins;
    notifyListeners();
  }
}



class AvatarRespList {
  String? mediaPath;
  String? mediaUrl;
  String? middleThumbUrl;
  String? thumbUrl;

  AvatarRespList(
      {this.mediaPath, this.mediaUrl, this.middleThumbUrl, this.thumbUrl});

  AvatarRespList.fromJson(Map<String, dynamic> json) {
    mediaPath = json['mediaPath'];
    mediaUrl = json['mediaUrl'];
    middleThumbUrl = json['middleThumbUrl'];
    thumbUrl = json['thumbUrl'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['mediaPath'] = this.mediaPath;
    data['mediaUrl'] = this.mediaUrl;
    data['middleThumbUrl'] = this.middleThumbUrl;
    data['thumbUrl'] = this.thumbUrl;
    return data;
  }
}

class TagDetails {
  String? tag;
  String? tagTip;
  String? tagColor;

  TagDetails({this.tag, this.tagTip, this.tagColor});

  TagDetails.fromJson(Map<String, dynamic> json) {
    tag = json['tag'];
    tagTip = json['tagTip'];
    tagColor = json['tagColor'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['tag'] = this.tag;
    data['tagTip'] = this.tagTip;
    data['tagColor'] = this.tagColor;
    return data;
  }
}

class MediaModel {
  String? mediaUrl;
  String? mediaPath;
  String? thumbUrl;
  String? mediaType;
  String? mediaId;
  XFile? imagePath;


  MediaModel({this.mediaUrl, this.mediaPath, this.thumbUrl, this.mediaType, this.mediaId,this.imagePath});

  MediaModel.fromJson(Map<String, dynamic> json) {
    mediaUrl = json['mediaUrl'];
    mediaPath = json['mediaPath'];
    thumbUrl = json['thumbUrl'];
    mediaType = json['mediaType'];
    mediaId = json['mediaId'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['mediaUrl'] = this.mediaUrl;
    data['mediaPath'] = this.mediaPath;
    data['thumbUrl'] = this.thumbUrl;
    data['mediaType'] = this.mediaType;
    data['mediaId'] = this.mediaId;
    return data;
  }
}
